#define _CRT_SECURE_NO_WARNINGS  1


class Solution {
public:
	void inorder(TreeNode* cur, TreeNode*& prev)
	{
		if (cur == nullptr)
			return;

		inorder(cur->left, prev);
		cur->left = prev;
		if (prev)
			prev->right = cur;
		prev = cur;
		inorder(cur->right, prev);
	}

	TreeNode* Convert(TreeNode* pRootOfTree)
	{
		TreeNode* prev = nullptr;
		inorder(pRootOfTree, prev);

		TreeNode* head = pRootOfTree;
		while (head && head->left)
		{
			head = head->left;
		}
		return head;

	}
};